package cn.ck.service.impl;


import cn.ck.dao.SysRoleMapper;
import cn.ck.pojo.SysRole;
import cn.ck.service.SysRoleService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysRoleServiceImpl implements SysRoleService {

    @Resource
    SysRoleMapper sysRoleMapper;
    @Resource
    RedisTemplate redisTemplate;

    @Override
    public List<SysRole> queryAllRoles() {
        Object queryAllRoles = redisTemplate.opsForValue().get("queryAllRoles");
        if (queryAllRoles != null){
            return (List<SysRole>) queryAllRoles;
        }
        List<SysRole> sysRoles = sysRoleMapper.queryAll();
        if (sysRoles != null){
            redisTemplate.opsForValue().set("queryAllRoles",sysRoles);
        }
        return sysRoles;
    }
}
